// SETUP

#include endepisodegraphics_jester.txt

// HELPER FUNCTIONS	

function signanimate(sign) {
	var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.show("loop");
}

function spinthewheel(sign, wheel) {
  var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.hide();
	
  wheel.x = 30;
  wheel.y = -30;
  play("spinthewheel");
	var s = wheel.show("spin1");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	wheel.hide();
}

// ACTORS

actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
actor("Robot", 150, screenheight - 100, 0xDDDDDD, LEFT, BOTTOM, "chat_robot", "characters/robot/charicon_robot");
// INTRO

play("music_cutscene_lesscheery");

changebackground("intro_sign");

sign.y = -screenheight;
jester.y = -screenheight;
sign.show("loop");
jester.show("idle");

Actuate.tween(sign, 2, { y: 0 }).ease(Expo.easeOut);
Actuate.tween(jester, 2, { y: 0 }).ease(Expo.easeOut);

wait(0.5);

fadein();

wait(1.5);

jester.show("talking");
actor("Jester", screenwidthmid, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "What a wonderful batch of contestants you all are!");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "And what a beautiful victory!");
jester.show("idle");

speak("Robot", "Thank you! I worked very hard!");

jester.show("talking");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "I can tell!");
actor("Jester", screenwidthmid, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "Now, fingers crossed as we SPIN THE WHEEL.");
speak("Jester", "Depending on how it lands, you’ll either walk away|with a prize, or we’ll invite you back to join us for|another episode!");
speak("Jester", "Actually I’m going to uncross my fingers|if that’s okay with you?");
actor("Jester", screenwidthmid + 300, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "The wheel’s really heavy and I|need to get a good grip...");
jester.show("idle");

speak("Robot", "That’s okay, I’ve got ALL my fingers and toes crossed.", "personality");
speak("Robot", "I know it doesn’t change the outcome of the|spin, but it helps me stay calm!");

jester.show("talking");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "Well, take a deep breath while the|WHEEL SPINS aaaaaand...");
jester.show("idle");

jester.hide();

spinthewheel(sign, wheel);

signanimate(sign);

jester.show("talking");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "...I’m so sorry!");
speak("Jester", "It looks like you don’t win a life without|sleep - at least, not just yet.");
actor("Jester", screenwidthmid + 200, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "But you DO take home a secret bonus prize:");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "An expired 50% off voucher for your|local pizza restaurant!");
actor("Jester", screenwidthmid + 200, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "And of course, you’ll get the chance to return|to the Dungeons in another episode...");
jester.show("idle");

gamecompletefromcutscene();
